package com.woniuxy.controller;

import com.woniuxy.service.UserService;
import com.woniuxy.util.Page;
import com.woniuxy.util.Result;
import com.woniuxy.vo.UserVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping("/user/selectUser")
    public Result selectUser(Integer index,Integer number) throws Exception{
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("index",index);
        map.put("number",number);
        List<UserVO> list = userService.selectUserByExample(map);
        int dataCount = userService.countUserByExample(map);
        int pageCount = dataCount%number==0?dataCount/number:dataCount/number+1;
        Page page = new Page(index,dataCount,pageCount,number);
        return new Result("200","success",page,list);
    }
}
